package org.minuframework.lang;

import java.text.NumberFormat;

public class MathUtils {

    /**
     * 百分比
     * 
     * @param param 小数
     * @param size 保留小数点位数
     * @return 百分比
     */
    public static String percent(double param, int size) {
        NumberFormat nf = NumberFormat.getPercentInstance();
        nf.setMaximumFractionDigits(size <= 0 ? 2 : size);
        String ab = nf.format(param);
        return ab;
    }

    public static void main(String[] args) {
        double param = 0.0487012987012987;
        System.out.println(percent(param, 0));
    }

    /**
     * 多一进一
     * 
     * @param total 总记录数
     * @param size 每页记录数
     * @return 总页数
     */
    public static int remaind(int total, int size) {
        int param = 0;
        if (total <= 0) {
            return param;
        }

        param = total / size;
        int remainder = total % size;
        if (remainder > 0) {
            param += 1;
        }

        return param;
    }

}
